<?php
/**
 * Notes:
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/10/26
 * Time: 18:42
 */

namespace app\model;


use think\Model;

class Rule extends Model
{
    public function getAllByPage(){
        return self::join('rule_group','rule.rule_group_id = rule_group.rule_group_id')
            ->select();
    }

    public function getById($rule_id){
        return self::get($rule_id);
    }
    public function getByGroup($rule_group_id){
        return self::where(['rule_group_id' => $rule_group_id])->select();
    }
    public function add($data){
        return self::create($data);
    }
    public function edit($rule_id,$data){
        return self::update($data,['rule_id' => $rule_id]);
    }
    public function rulegroup(){
        return $this->hasOne('RuleGroup','rule_group_id','rule_group_id');
    }
    public function checkName($rule_name){
        return self::get(['rule_name' => $rule_name]);
    }
    public function checkKey($rule_key){
        return self::get(['rule_key' => $rule_key]);
    }
    public function checkGroup($rule_group_id){
        return self::get(['rule_group_id' => $rule_group_id]);
    }
    public function getRuleTimeAttr($value){
        return date('Y-m-d H:i',$value);
    }

}